#!/usr/bin/python
# -*- coding: UTF-8 -*-


import time
import robotlib
import oppleserialmsg


GENERAL_TIMEOUT = 1

'''
common testing, will testing all interface
'''
def testcase1(serialclass):
    # get wifi boot type
    ret, boottype = serialclass.get_boot_type(10)
    if (ret != "success"):
        print ret
        return "failed"

    print "********"
    print "boottype %d" % boottype
    print "********"

    time.sleep(1)

    # get wifi netlink and rssi
    netlink = 0
    while netlink != 7:
        ret, netlink, rssi = serialclass.get_network(10)
        if (ret != "success"):
            print ret
            continue

        print "********"
        print "netlink %d rssi %d" % (netlink, rssi)
        print "********"

    time.sleep(6)

    # uart ping test
    ret = robotlib.port_tesing(serialclass, 10, GENERAL_TIMEOUT)
    if (ret != "success"):
        print ret
        return "failed"

    time.sleep(1)

    # get uptime
    time.sleep(2)
    ret, uptime, mac = serialclass.get_uptime_mac(GENERAL_TIMEOUT)
    if (ret != "success"):
        print ret
        return "failed"

    print "********"
    print "uptime %dms mac %02x:%02x:%02x:%02x:%02x:%02x" % (uptime, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])
    print "********"

    time.sleep(1)

    # reboot communication
    ret = serialclass.reboot(GENERAL_TIMEOUT)
    if (ret != "success"):
        print ret
        return "failed"

    time.sleep(1)

    # switch on communication
    ret = serialclass.onoff_status(1, GENERAL_TIMEOUT)
    if (ret != "success"):
        print ret
        return "failed"

    time.sleep(1)

    # switch off communication
    ret = serialclass.onoff_status(0, GENERAL_TIMEOUT)
    if (ret != "success"):
        print ret
        return "failed"

    cnt = 0
    while cnt < 10:
        ret, onoff = serialclass.wait_onoff_req(10)
        if (ret != "success"):
            print ret
            continue

        cnt += 1
        print "********"
        print "onoff %d" % (onoff)
        print "********"

    return "success"